package com.yidu.t299.service.ljc.impl;
import com.yidu.t299.dao.ljc.OutstockcopyMapper;
import com.yidu.t299.domain.ljc.Outstockcopy;
import com.yidu.t299.service.ljc.OutstockcopyBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * @author 刘建常
 * @version 1.0
 * @description
 * @date:2023/3/8 10:53
 */
@Service
@Transactional
public class OutstockcopyBizImpl implements OutstockcopyBiz {
    @Autowired
    private OutstockcopyMapper outstockcopyMapper;

    @Override
    public int deleteByPrimaryKey(Integer outId) {
        return outstockcopyMapper.deleteByPrimaryKey(outId);
    }

    @Override
    public int insert(Outstockcopy record) {
        return outstockcopyMapper.insert(record);
    }

    @Override
    public Outstockcopy selectByPrimaryKey(Integer outId) {
        return outstockcopyMapper.selectByPrimaryKey(outId);
    }

    @Override
    public List<Outstockcopy> selectByPage(int rows, int page, String condition) {
        return outstockcopyMapper.selectByPage(rows, page, condition);
    }

    @Override
    public int selectCount(String condition) {
        return outstockcopyMapper.selectCount(condition);
    }

    @Override
    public int updateByPrimaryKey(Outstockcopy record) {
        return outstockcopyMapper.updateByPrimaryKey(record);
    }

    @Override
    public String getCondition(Outstockcopy record) {
        // 定义条件字符串变量，初始值为空格字符串
        String condition = " ";
        // 如果校区对象为空，则直接返回空条件字符串
        if (record == null) {
            return condition;
        }
        // 如果校区编号不为空(如果是基本类型就直接判断!=0)
        if (record.getOutId() != null) {
            condition += " and input_stock_id = " + record.getOutId();
        }

        if (record.getTextbookName() != null && record.getAuthor().trim().length() != 0) {
            condition += " and textbook_name = " + record.getTextbookName();
        }

        // 如果校区名称不为空
        if (record.getAuthor() != null && record.getAuthor().trim().length() != 0) {
            condition += " and author like '%" + record.getAuthor() + "%'";
        }

        if (record.getPublishingCompany() != null && record.getPublishingCompany().trim().length() != 0) {
            condition += " and publishing_company = " + record.getPublishingCompany() + "%'";
        }

        if (record.getTextbookNum() != null ) {
            condition += " and textbook_num like '%" + record.getTextbookNum() + "%'";
        }

        if (record.getCollecting() != null && record.getCollecting().trim().length() != 0) {
            condition += " and collecting = " + record.getCollecting() + "%'";
        }

        if (record.getOutStock() != null && record.getOutStock().trim().length() != 0) {
            condition += " and out_stock_date = " + record.getOutStock() + "%'";
        }

        if (record.getHandled() != null && record.getHandled().trim().length() != 0) {
            condition += " and handled = " + record.getHandled() + "%'";
        }

        // 返回条件字符串
        return condition;
    }
}
